package com.stephentuso.welcomeexample;

import com.stephentuso.welcome.BasicPage;
import com.stephentuso.welcome.TitlePage;
import com.stephentuso.welcome.WelcomeAbility;
import com.stephentuso.welcome.WelcomeConfiguration;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;

/**
 * Created by stephentuso on 11/16/16.
 */

public class ButtonBarWelcomeAbility extends WelcomeAbility {

    private static final int REQUEST_CODE_LOG_IN_SIGN_UP = 100;

    @Override
    protected WelcomeConfiguration configuration() {
        return new WelcomeConfiguration.Builder(this)
                .canSkip(false)
                .backButtonNavigatesPages(false)
                .defaultTitleTypefacePath("Roboto-Bold.ttf")
                .defaultHeaderTypefacePath("Roboto-Bold.ttf")
                .bottomLayout(WelcomeConfiguration.BottomLayout.BUTTON_BAR)
                .page(new TitlePage(this, ResourceTable.Graphic_ic_image_white, "Title Page"))
                .page(new BasicPage(this, ResourceTable.Graphic_ic_image_white, "Basic Page", "A page with a title and description").background(ResourceTable.Color_purple_background))
                .build();
    }

    @Override
    protected void onButtonBarFirstPressed() {
        showExampleActionAbility("Log In");
    }

    @Override
    protected void onButtonBarSecondPressed() {
        showExampleActionAbility("Sign Up");
    }

    private void showExampleActionAbility(String action) {
        Operation operation = new Intent.OperationBuilder()
                .withBundleName("com.stephentuso.welcomeexample")
                .withAbilityName(ExampleActionAbility.class)
                .build();
        Intent intent = new Intent();
        intent.setParam(ExampleActionAbility.KEY_ACTION_TITLE, action);
        intent.setOperation(operation);
        startAbilityForResult(intent, REQUEST_CODE_LOG_IN_SIGN_UP);
    }

    @Override
    protected void onAbilityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_CODE_LOG_IN_SIGN_UP && resultCode == -1) {
            completeWelcomeScreen();
            return;
        }
        super.onAbilityResult(requestCode, resultCode, data);
    }
}
